package com.lordjoe.collectiveintelligence.svm.matchmaker;

import com.lordjoe.collectiveintelligence.*;
import com.lordjoe.collectiveintelligence.svm.*;

import java.util.*;

/**
 * com.lordjoe.collectiveintelligence.svm.PotentialDate
 *
 * @author Steve Lewis
 * @date May 20, 2009
 */
public class PotentialDate
{
    public static PotentialDate[] EMPTY_ARRAY = {};
    public static Class THIS_CLASS = PotentialDate.class;
    public static final int NUMBER_TEXT_ITEMS = 5;

    public static PotentialDate buildPotentialDate(String[] items, Sex sx, int start)
    {
        PotentialDate ret = new PotentialDate();
        ret.setSex(sx);
        String s = null;

        s = items[start++];
        ret.setAge(Integer.parseInt(s.trim()));

        s = items[start++];
        ret.setSmoker(SVMUtilities.fromYesNo(s));

        s = items[start++];
        ret.setChildrenWanted(SVMUtilities.fromYesNo(s));

        s = items[start++];
        String[] interests = s.split(",");
        ret.addInterests(interests);

        s = items[start++];
        ret.setAddress(s);
        return ret;
    }


    private Sex m_Sex;
    private int m_Age;
    private String m_Address;
    private LatLon m_LatLon;
    private boolean m_Smoker;
    private boolean m_ChildrenWanted;
    private final Set<String> m_Interests =  new HashSet<String>();

    public PotentialDate()
    {
    }

    public Sex getSex()
    {
        return m_Sex;
    }

    public void setSex(Sex pSex)
    {
        m_Sex = pSex;
    }

    public int getAge()
    {
        return m_Age;
    }

    public void setAge(int pAge)
    {
        m_Age = pAge;
    }

    public boolean isSmoker()
    {
        return m_Smoker;
    }

    public void setSmoker(boolean pSmoker)
    {
        m_Smoker = pSmoker;
    }

    public boolean isChildrenWanted()
    {
        return m_ChildrenWanted;
    }

    public void setChildrenWanted(boolean pChildrenWanted)
    {
        m_ChildrenWanted = pChildrenWanted;
    }

    public Set<String> getInterests()
    {
        return m_Interests;
    }

    public String getInterestsString()
    {
        StringBuilder sb = new StringBuilder();
        for(String s : getInterests()) {
            if(sb.length() > 0)
                sb.append(",");
            sb.append(s);
        }
        return sb.toString();
    }

     public void addInterests(String[] pInterests)
    {
        for (int i = 0; i < pInterests.length; i++) {
            String interest = pInterests[i];
            m_Interests.add(interest);
        }
    }

    public boolean hasInterest(String interest)
    {
        return m_Interests.contains(interest);
    }

    public String getAddress()
    {
        return m_Address;
    }

    public void setAddress(String pAddress)
    {
        m_Address = pAddress;
    }

    public LatLon getLatLon()
    {
        if(m_LatLon == null) {
            String addr = getAddress();
            m_LatLon = GeoCodeUtilitiies.getLatLon(addr);
        }
        return m_LatLon;
    }

    public void setLatLon(LatLon pLatLon)
    {
        m_LatLon = pLatLon;
    }
}
